#include <stdio.h>

#define LEN 16

typedef struct {
	int data[16];
	int pos;
} stack_t;

void push(stack_t *s, int data)
{
	s->data[s->pos] = data;
	s->pos++;
}

int pop(stack_t *s)
{
	return s->data[s->pos--];
}

void init_stack(stack_t *s)
{
	s->pos = 0;
}

int top(stack_t *s)
{
	if (s->pos > 0) 
		return s->data[s->pos - 1];
	return 0;
}

int empty(stack_t *s) 
{
	if (s->pos == 0)
		return 1;
	return 0;
}

int check_seq(int *in, int *out, int len)
{
	int i = 0, j = 0, ret = 0, t;
	stack_t s[1];
	
	while (i < len) {
		if (empty(s)) {	
			if (j < len) {
				push(s, in[j++]);
				continue;
			}
			else {
				ret = -1;
				break;
			}
		}

		t = top(s);
		if (t == out[i]) {
			pop(s);
			i++;
		} else {
			if (j < len)
				push(s, in[j++]);
			else {
				ret = -1;
				break;
			}
		}
	}

	return ret;
}

int main()
{
	int push[5] = {1, 2, 3, 4, 5};
	//int pop[5] = {4, 5, 3, 2, 1};
	int pop[5] = {5, 4, 3, 1, 2};
	int ret = 0;

	ret = check_seq(push, pop, 5);

	return ret;
}
